//
//  TF1to16NavigationBarTools.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/17.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit
import AFNetworking
public class TF1to16NavigationBarTools: TalkfunHitTestView {
    //上面黑色阴影
    @objc let topView = TalkfunHitTestView()
    @objc var isTopViewadd:Bool = false
    @objc var buttonArray: [Int] = []

    //询问黑色阴影
    @objc let bottomView = TalkfunHitTestView()
    @objc let bottomStackView = UIStackView()
    @objc let back = TalkfunIncreaseButton()
    @objc let time = UIButton()
    @objc let title = UILabel()
    @objc let refresh = TalkfunIncreaseButton()
    //线路设置
    @objc let setButton = TalkfunIncreaseButton()
    //设置
    @objc let setButtonTools = TalkfunIncreaseButton()
    
   //线路
    @objc let networkStatus = TalkfunIncreaseButton()
    //大班互动切换
    @objc let switchButton = UIButton()
    //放大缩小按键
    
//    @objc let fullButton = UIButton()

    @objc let isFullButton = TFCenteredleLabel()
    //弹幕
    @objc let barrage = UIButton()
    //聊天
    @objc let chat = TFRoundBackground()
    @objc let video = UIButton()
    @objc let audio = UIButton()
    //前后摄像头
    @objc let frontAndRearCamera = UIButton()
    //输入栏
    @objc let inputField = TFMsg()
    @objc let inputFieldButton = UIButton()
    //举手
    @objc let ondium = TFOnPodiumButton()
    //提问
    @objc let askQuestions = TFCenteredleLabel()
    //投票
    @objc let voteBtn = TFCenteredleLabel()
    //配置后台聊天功能,true:默认是开启的,false隐藏聊天
    @objc var showChat:Bool = true
    //配置后台问答功能,true:默认是开启的,false隐藏问答按钮
    @objc var showQa:Bool = true
    //配置后台申请按钮,true:默认是开启的,false隐藏申请按钮
    @objc var showOndium:Bool = true
    //配置后台投票按钮,true:默认是开启的,false隐藏申请按钮
    @objc var showVote:Bool = true
    //大班互动.在讲台上摄像头图标切换
    @objc var isOndium:Bool = true
    //配置后台课件下载,true:默认是开启的,false隐藏申请按钮
    @objc var showCourseDown:Bool = true
    //课件下载
    @objc let courseDownBtn = UIButton()

    let topGl = CAGradientLayer()
    
    let bottomGl = CAGradientLayer()

    //是不是wifi 切换 为 4G
    @objc var wirelessLocalAreaNetworkIntoNobileNetwork:Bool = false

    //记录   用于判断最后 一次的网络 是不是wifi
    @objc var lastNetworkState:NSInteger = 0
    @objc var take:Bool = false
    @objc var start:Bool = false

    var model:String = ""
    var smalltype:String = ""
    var shipintype:String = ""

    @objc func destroy()
    {
        NotificationCenter.default.removeObserver(self)
    }
    @objc func ReachabilityDidChange(notification:NSNotification)
  
    {
        let params = notification.userInfo! as NSDictionary
        let Reacha =  params[AFNetworkingReachabilityNotificationStatusItem] as! NSNumber
      
        
        let  status  = NSInteger(Reacha.intValue)
        
        self.networkReachabilityStatus(status)
    
    }
    func networkReachabilityStatus(_ status:NSInteger)

    {   let  ReachabilityStatusUnknown          = -1
        let  ReachabilityStatusNotReachable     = 0
        let  ReachabilityStatusReachableViaWWAN = 1
        let  ReachabilityStatusReachableViaWiFi = 2
        
            //网络变更新 时  no
            self.wirelessLocalAreaNetworkIntoNobileNetwork  = false;
            
            switch (status) {
                case ReachabilityStatusReachableViaWiFi:
                self.networkStatus.setImage(UIImage.init(named: "HTLive.bundle/wifi1vN"), for: .normal)
                     
                    break;
                case ReachabilityStatusReachableViaWWAN:
        //  NSLog(@"手机自带网络");
                self.networkStatus.setImage(UIImage.init(named: "HTLive.bundle/phoneNetwork1vN"), for: .normal)
                     
                    if (self.lastNetworkState == ReachabilityStatusReachableViaWiFi) {
                        self.wirelessLocalAreaNetworkIntoNobileNetwork  = true
                    }
                    
                    break;
                case ReachabilityStatusNotReachable:
                    //没有网络
                self.networkStatus.setImage(UIImage.init(named: "HTLive.bundle/notReachable1vN"), for: .normal)
                    
                    break;
                case ReachabilityStatusUnknown:
                    //未知网络
                self.networkStatus.setImage(UIImage.init(named: "HTLive.bundle/notReachable1vN"), for: .normal)
                     
                    break
                default:
                    break
            }
            self.lastNetworkState = status
    }
    
    @objc func addTopViewAndBottomView()
    
    {
        if (self.isTopViewadd == false) {
            self.isTopViewadd = true
            
            let networkReachabilityManager =     AFNetworkReachabilityManager.shared()
             
            networkReachabilityManager.startMonitoring()
            
            //TODO:监听全局网络状态
            NotificationCenter.default.addObserver(self, selector: #selector(self.ReachabilityDidChange), name: Notification.Name(NSNotification.Name.AFNetworkingReachabilityDidChange.rawValue), object: nil)
            
            
            self.addSubview(self.topView)

            self.topView.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: 110)
            
                let topViewBackgroundColor = UIView()
                 topViewBackgroundColor.isUserInteractionEnabled = false
                topViewBackgroundColor.frame = self.topView.bounds
            self.topView.addSubview(topViewBackgroundColor)


            
            self.topGl.startPoint = CGPoint(x: 0.5, y: 0)
            self.topGl.endPoint = CGPoint(x: 0.5, y: 1)
            
            self.topGl.colors = [UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.90).cgColor, UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.00).cgColor]
            self.topGl.locations = [0,1]
            topViewBackgroundColor.layer.addSublayer(self.topGl)
             
    
            self.topGl.frame = topViewBackgroundColor.bounds


            self.back.backgroundColor = UIColor.clear
            self.back.setImage(UIImage.init(named: "HTLive.bundle/back_1"), for: .normal)
           
            self.topView.addSubview(self.back)

            //TODO:时间
   
            self.time.isHidden = true
            self.time.backgroundColor = UIColor.clear
            self.time.setTitle("  00:00:00", for: .normal)
            self.time.setImage(UIImage.init(named: "HTLive.bundle/time"), for: .normal)
            self.time.titleLabel!.font = UIFont.systemFont(ofSize: 14)
            self.topView.addSubview(self.time)
            self.time.isUserInteractionEnabled = false

            //TODO: 标题
       
            self.title.font = UIFont.systemFont(ofSize: 17)
            self.title.text = ""
            self.title.textColor =  UIColor.white
            self.topView.addSubview(self.title)

   
            self.refresh.contentMode = .scaleToFill
            self.refresh.setImage(UIImage.init(named: "HTLive.bundle/refresh1vN"), for: .normal)
            self.topView.addSubview(self.refresh)

           //线路设置
            self.setButton.contentMode = .scaleToFill
            self.setButton.setImage(UIImage.init(named: "HTLive.bundle/networkSelection1vN"), for: .normal)
            self.topView.addSubview(self.setButton)
            
            //设置按键
//            self.setButtonTools.contentMode = .scaleToFill
//            self.setButtonTools.setImage(UIImage.init(named: "HTLive.bundle/selection1vN"), for: .normal)
//            self.topView.addSubview(self.setButtonTools)
            
            //网络状态
 
            self.networkStatus.isUserInteractionEnabled = false
            self.networkStatus.contentMode = .scaleToFill
            self.networkReachabilityStatus(AFNetworkReachabilityManager.shared().networkReachabilityStatus.rawValue)
          
            self.topView.addSubview(self.networkStatus)
            self.addSubview(self.bottomView)
            self.bottomView.frame = CGRect(x:0 , y: self.frame.size.height-110, width: self.frame.size.width, height: 110)

             let bottomBackgroundColor = UIView()
            bottomBackgroundColor.frame = self.bottomView.bounds
//            self.bottomStackView.frame = self.bottomView.bounds
             bottomBackgroundColor.isUserInteractionEnabled = false
            
            self.bottomView.addSubview(bottomBackgroundColor)
            self.bottomView.addSubview(bottomStackView)
            self.bottomStackView.distribution = .fillEqually
            self.bottomStackView.spacing = 20
            self.bottomStackView.alignment = .leading
            self.bottomGl.startPoint = CGPoint(x: 0.5, y: 0)
            self.bottomGl.endPoint = CGPoint(x: 0.5, y: 1)
            
            self.bottomGl.colors = [UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.00).cgColor, UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.90).cgColor]
            self.bottomGl.locations = [0,1]
            
            
            bottomBackgroundColor.layer.addSublayer(self.bottomGl)
             self.bottomGl.frame = bottomBackgroundColor.bounds
   
            self.inputField.textColor = UIColor.white
            self.upDataLanguage()
            self.bottomView.addSubview(self.inputField)
            self.inputField.backgroundColor = UIColor(red:255/255.0, green:255/255.0, blue :255/255.0, alpha: 0.3)
            self.inputField.layer.cornerRadius = 18
            self.inputField.addSubview(inputFieldButton)
            
            self.setButtonTools.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.setButtonTools)
            self.setButtonTools.setImage(UIImage.init(named: "HTLive.bundle/selection1vN"), for: .normal)
           
            
            
            self.switchButton.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.switchButton)
            self.switchButton.setImage(UIImage.init(named: "HTLive.bundle/bigPpt"), for: .normal)

            self.barrage.tag = 1
            self.barrage.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.barrage)
            self.barrage.setImage(UIImage.init(named: "HTLive.bundle/barrage1vN"), for: .normal)
            
            self.chat.fullScreen = true
            self.chat.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.chat)
            self.chat.setImage(UIImage.init(named: "HTLive.bundle/chat1vN"), for: .normal)
            
            self.video.tag = 1
            self.video.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.video)
            self.video.setImage(UIImage.init(named: "HTLive.bundle/video1vN"), for: .normal)
          
            self.audio.tag = 1
            self.audio.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.audio)
            self.audio.setImage(UIImage.init(named: "HTLive.bundle/audio1vN"), for: .normal)
         
            self.frontAndRearCamera.tag = 1
            self.frontAndRearCamera.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.frontAndRearCamera)
            self.frontAndRearCamera.setImage(UIImage.init(named: "HTLive.bundle/frontAndRearCamera"), for: .normal)
          
            self.ondium.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.ondium)
            self.ondium.imageView?.contentMode = .scaleAspectFit
            
            self.askQuestions.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.askQuestions)
            self.askQuestions.setImage(UIImage.init(named: "HTLive.bundle/asked"), for: .normal)
          
            self.voteBtn.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.voteBtn)
            self.voteBtn.setImage(UIImage.init(named: "HTLive.bundle/voteimg"), for: .normal)

            self.courseDownBtn.setImage(UIImage.init(named: "HTLive.bundle/smallbandown"), for: .normal)
            self.bottomStackView.addArrangedSubview(self.courseDownBtn)

//            fullButton
            self.isFullButton.layer.cornerRadius = 4
            self.bottomStackView.addArrangedSubview(self.isFullButton)
            self.isFullButton.setImage(UIImage.init(named: "HTLive.bundle/fullScreen1vN"), for: .selected)
            
            self.isFullButton.setImage(UIImage.init(named: "HTLive.bundle/shrink1vN"), for: .normal)
//            self.isFullButton.imageEdgeInsets = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
            self.back.frame = CGRect(x:0 , y: 10, width: 50, height: 18)
       

            let timeW:CGFloat = 110
            //  83 +15
            let timeX:CGFloat =  (self.frame.size.width - timeW )/2

            self.time.frame = CGRect(x: timeX, y: 0, width: timeW, height: 35)
            

            let nameX:CGFloat =  self.back.frame.size.width
            let nameY:CGFloat = self.back.frame.origin.y
            let nameWidth:CGFloat = self.frame.size.width  -  nameX - timeW
            let nameHeight:CGFloat = self.back.frame.size.height
            self.title.frame = CGRect(x: nameX, y: nameY, width: nameWidth, height: nameHeight)
           
         
        }
      
    }
    
    @objc func upDataLanguage()
    {
        let string = NSMutableAttributedString.getAttributed(string: "我要发言...", font: UIFont.PingFang(size: 15), foregroundColor: UIColor(red:255/255.0, green:255/255.0, blue: 255/255.0, alpha: 1))
        
        //边距 间距
        self.inputField.attributedPlaceholder = string
        
        
        
    }
    @objc func updateCourseDownStatus(_ showCourseDown:Bool)

    {
        self.showCourseDown = showCourseDown
        self.takeThePodium(self.take, liveStart: self.start, modetype: self.model, smallType: self.smalltype, shipinType: self.shipintype)

    }

    //6大班互动模式
    //5小班模式
    //3大班模式
    //1:一对一,2:1vs6,3:1vs16
    // 上讲台     开直播     课程类型  小班类型 视频模式(课件  主讲 画廊)
    
    @objc func takeThePodium(_ take:Bool,liveStart:Bool,modetype:String,smallType:String,shipinType:String)
    {
        
        self.take = take
        self.start = liveStart
        self.model = modetype
        self.smalltype = smallType
        self.shipintype = shipinType
        if (take == false) {
          
            //已经开始直播但未上讲台而已  5 = 纯小班
            if (start==true && (model == "5")) {
                self.networkStatus.isHidden = false
                self.refresh.isHidden = false
                self.switchButton.isHidden = true;
                
                
                if (shipintype == "0") {
                       self.isFullButton.isHidden = false
                    
//                    //self.isFullButton.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                } else {
                    //改动
                       self.isFullButton.isHidden = false
//                    //self.isFullButton.frame = CGRect(x: self.frame.size.width, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                }
              
               
                self.barrage.isHidden = true;

//                self.barrage.frame = self.isFullButton.frame
                
                self.refresh.frame = CGRect(x: self.frame.size.width - 37 - 13, y: 6, width: 37, height: 37)
                
//                self.setButtonTools.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
                
                
                self.setButtonTools.isHidden = false
                self.setButton.isHidden = true;
                self.setButton.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
                
                self.networkStatus.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
            }else{
                
                self.isFullButton.isHidden = false
                
                self.refresh.frame = CGRect(x: self.frame.size.width - 37 - 13, y: 6, width: 37, height: 37)
                
                
                self.setButtonTools.isHidden = false
//                self.setButtonTools.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
               
                
                //直播开始了 6 == 大班互动
                if (start&&( model == "6")) {
                    self.refresh.isHidden = false
                    self.networkStatus.isHidden = false
                    self.setButton.isHidden = false
                    self.switchButton.isHidden = false
                    
//                    self.switchButton.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    self.barrage.isHidden = true

//                    self.barrage.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
                    
                    self.setButton.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
                   
                    self.networkStatus.frame = CGRect(x: self.setButton.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
                }else{
                
                    
                    //直播结束了
                    
                    self.setButton.isHidden = true
                    
                    self.switchButton.isHidden = true
                    self.refresh.isHidden = true
                    self.refresh.isHidden = false
                    
                    self.networkStatus.isHidden = true
                    self.barrage.isHidden = true
                    
                    
                    
//                    self.barrage.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                    self.setButton.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
                }
                

               
            }
            //6 == 大班互动
            if (model == "6") {
                self.chat.isHidden = false
                if (shipintype=="0") {
                    
                    
//                    self.chat.frame = CGRect(x: self.barrage.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                } else {
//                   self.chat.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                }
            } else {
                /**配置后台聊天限制*/
                 if (self.showChat) {
                     self.chat.isHidden = false
                     if (shipintype=="0") {
//                         self.chat.frame = CGRect(x: self.barrage.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                         
                         
                     } else {
//                        self.chat.frame = CGRect(x:self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                         
                        
                     }
                
                 } else {
                     self.chat .isHidden = true;
                     if (shipintype=="0") {
//                         self.chat.frame = self.barrage.frame
                     } else {
//                         self.chat.frame = self.frame
                     }
                
                 }
            }

            if (smalltype == "1") {
                self.askQuestions.isHidden = true
                self.voteBtn.isHidden = true
                self.ondium.isHidden = true
//                self.ondium.frame = CGRect(x: self.barrage.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
                
                
            } else if (smalltype == "2") {
                self.ondium.isHidden = true
                self.askQuestions.isHidden = true
             
//                self.askQuestions.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
                
              
               //配置小班互动模式后台对投票的设置.
                if (model == "6"||self.showVote) {
                    self.voteBtn.isHidden = false
//                    self.voteBtn.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
//                    self.ondium.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                } else {
                    self.voteBtn.isHidden = true
//                    self.voteBtn.frame = self.askQuestions.frame
//                    self.ondium.frame = self.voteBtn.frame
                }
               
               
            } else {
              
              
                if (model == "6") {
                    self.askQuestions.isHidden = false
//                    self.askQuestions.frame = CGRect(x: self.chat.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                } else {
                    if (self.showQa) {
                        self.askQuestions.isHidden = false
//                        self.askQuestions.frame = CGRect(x: self.chat.frame.origin.x - 20 - 37, y:  self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                        
                    } else {
                        self.askQuestions.isHidden = true
//                        self.askQuestions.frame = self.chat.frame
                    }
                }
               
                if (model == "6" || self.showVote) {
                    
                    self.voteBtn.isHidden = false
//                    self.voteBtn.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                    
                    
//                    self.ondium.frame = CGRect(x:self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                } else {
                    self.voteBtn.isHidden = true;
//                    self.voteBtn.frame = self.askQuestions.frame;
//                    self.ondium.frame = self.voteBtn.frame;
                }

                self.ondium.isHidden = true;
               
            }
            
            //课件下载
            if (self.showCourseDown) {
                self.courseDownBtn.isHidden = false
//                self.courseDownBtn.frame = CGRect(x: self.ondium.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
                
            } else {
                self.courseDownBtn.isHidden = true;
//                self.courseDownBtn.frame = self.ondium.frame;
            }
            buttonArray = []
            var viewsWidth:CGFloat = 0
            var count = 0
            for i in 0...(self.bottomStackView.arrangedSubviews.count - 1){
                let view = self.bottomStackView.arrangedSubviews[i]
                if !view.isHidden{
                    count = count + 1
                    buttonArray.append(i)
                    print("+++++++++++\(viewsWidth), \(count)")
                }
            }
            viewsWidth = CGFloat(self.buttonArray.count * 36 + (self.buttonArray.count - 1) * 20)
            self.bottomStackView.frame = CGRect(x: CGRectGetWidth(self.bottomView.frame) - viewsWidth - 30, y: self.bottomView.frame.size.height - 8 - 36, width: viewsWidth, height: 36)
            self.inputField.frame =  CGRect(x: 25, y: self.bottomView.frame.size.height - 8 - 36, width: CGRectGetWidth(self.bottomView.frame) - viewsWidth - 100, height: 36)
            
           
            
            self.frontAndRearCamera.isHidden = true
            self.video.isHidden = true
            self.audio.isHidden = true

        }else{
             self.networkStatus.isHidden = false
              self.refresh.isHidden = false
        if (model == "5") {
            self.setButton.isHidden = true
            self.setButton.frame =  CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
           
            self.networkStatus.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
        } else {
            self.setButton.isHidden = false
            self.setButton.frame = CGRect(x: self.refresh.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
            
            
            
            self.networkStatus.frame = CGRect(x: self.setButton.frame.origin.x - 37 - 13, y: 6, width: 37, height: 37)
        }

             self.setButtonTools.isHidden = false
          
            
            if (shipintype == "0") {
                self.isFullButton.isHidden = false
                //self.isFullButton.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
                
                
            } else {
                self.isFullButton.isHidden = false;
                //self.isFullButton.frame = CGRect(x: self.frame.size.width, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
               
            }
            if (model == "6") {
                if (self.isOndium) {
                    self.switchButton.isHidden = true
                       self.isFullButton.isHidden = false
                } else {
                    self.switchButton.isHidden = false
                       self.isFullButton.isHidden = false
                }
            }
            
            
//             self.frontAndRearCamera.frame = CGRect(x: self.isFullButton.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
            
            
//            self.video.frame =  CGRect(x: self.frontAndRearCamera.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
           
            
                   
//            self.audio.frame = CGRect(x: self.video.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
           
            

//            self.barrage.frame = CGRect(x: self.audio.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
            
            

            self.video.isHidden = true
            self.audio.isHidden = true
            self.barrage.isHidden = true
            self.frontAndRearCamera.isHidden = true
//            self.barrage.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
            
            
            if (smalltype == "1") {

                if (shipintype == "0") {
                    if (self.showVote) {
                        self.voteBtn.isHidden = false
//                        self.voteBtn.frame = CGRect(x: self.isFullButton.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                        
                    } else {
                        self.voteBtn.isHidden = true
//                        self.voteBtn.frame = self.isFullButton.frame
                    }
                    
                } else {

                    if (self.showVote) {
                        self.voteBtn.isHidden = false
//                        self.voteBtn.frame = CGRect(x: self.frame.size.width - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                      
                        
                    } else {
                        self.voteBtn.isHidden = true;
//                        self.voteBtn.frame =  CGRect(x: self.frame.size.width, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                       
                    }
                   
                   
                }
                    
                    
                /**防止hud */
                if (model == "6") {
                    self.chat.isHidden = false

//                    self.chat.frame = CGRect(x: self.voteBtn.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                } else {
                    if (self.showChat) {
                        self.chat.isHidden = false
//                        self.chat.frame =  CGRect(x: self.voteBtn.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                       
                    } else {
                        self.chat.isHidden = true;

//                        self.chat.frame = self.voteBtn.frame;
                    }
                       
                }
             
               
                
            }else{

                if (model == "6") {
                    self.chat.isHidden = false
//                    self.chat.frame = CGRect(x: self.isFullButton.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                } else {
                    /**配置后台聊天限制*/
                    if (self.showChat) {
                        self.chat.isHidden = false
//                        self.chat.frame = CGRect(x: self.isFullButton.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                        
                    } else {
                        self.chat.isHidden = true;
//                        self.chat.frame = self.isFullButton.frame;
                    }
                }
              
            
            }
            
            
          
            if (smalltype == "1") {
           //注释的有争议,在添加课件下载动态按钮的时候,注释这个ondium.frame 有问题
                
                if (self.showChat) {
//                    self.ondium.frame = CGRect(x: self.voteBtn.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                } else {
//                    self.ondium.frame = self.voteBtn.frame
                }
             
                self.ondium.isHidden = true;
                self.askQuestions.isHidden = true;
            } else if (smalltype == "2") {
                self.ondium.isHidden = true
                self.askQuestions.isHidden = true
//                self.askQuestions.frame = self.chat.frame
                if (self.showVote) {
                    self.voteBtn.isHidden = false
//                    self.voteBtn.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
//                    
//                    
//                    self.ondium.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                } else {
                    self.voteBtn.isHidden = true;
//                    self.voteBtn.frame = self.askQuestions.frame;
//                    self.ondium.frame = self.voteBtn.frame;
                }
                
                
            } else {
                if (model == "6") {
                    self.askQuestions.isHidden = false
//                    self.askQuestions.frame = CGRect(x: self.chat.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                    
                } else {
                    if (self.showQa) {
                        self.askQuestions.isHidden = false
//                        self.askQuestions.frame =  CGRect(x: self.chat.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                       
                    } else {
                        self.askQuestions.isHidden = true;
//                        self.askQuestions.frame = self.chat.frame;
                    }
           
                }

                if (model == "6" || self.showVote) {
                    self.voteBtn.isHidden = false
//                    self.voteBtn.frame = CGRect(x: self.askQuestions.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                } else {
                    self.voteBtn.isHidden = true;
//                    self.voteBtn.frame = self.askQuestions.frame;
                }
              
                if (model == "6") {
//                    self.ondium.frame = CGRect(x: self.voteBtn.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                    
                    
                    self.ondium.isHidden = false
                } else{
                    if (self.showOndium) {
//                        self.ondium.frame = CGRect(x: self.voteBtn.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                        
                        
                        self.ondium.isHidden = false
                    } else {
//                        self.ondium.frame = self.voteBtn.frame
                        self.ondium.isHidden = true;
                    }
                }
                
              
            }
              
            //课件下载
            if (self.showCourseDown) {
                self.courseDownBtn.isHidden = false
//                self.courseDownBtn.frame =  CGRect(x: self.ondium.frame.origin.x - 20 - 37, y: self.bottomView.frame.size.height - 7.5 - 37, width: 37, height: 37)
                
               
                
            } else {
                self.courseDownBtn.isHidden = true;
//                self.courseDownBtn.frame = self.ondium.frame;
            }
//            let inputFieldW:CGFloat = self.courseDownBtn.frame.origin.x - 20 - 25
//            self.inputField.frame = CGRect(x: 25, y: self.bottomView.frame.size.height - 8 - 36, width: inputFieldW, height: 36)
            buttonArray = []
            var viewsWidth:CGFloat = 0
            var count = 0
            for i in 0...(self.bottomStackView.arrangedSubviews.count - 1){
                let view = self.bottomStackView.arrangedSubviews[i]
                if !view.isHidden{
//                    viewsWidth = viewsWidth + 40 + 10
                    count = count + 1
                    buttonArray.append(i)
                    print("+++++++++++\(viewsWidth), \(count)")
                }
            }
            viewsWidth = CGFloat(count * 36 + (count - 1) * 20)
            self.bottomStackView.frame = CGRect(x: CGRectGetWidth(self.bottomView.frame) - viewsWidth - 30, y: self.bottomView.frame.size.height - 8 - 36, width: viewsWidth, height: 36)
            self.inputField.frame =  CGRect(x: 25, y: self.bottomView.frame.size.height - 8 - 36, width: CGRectGetWidth(self.bottomView.frame) - viewsWidth - 100, height: 36)
            

        }
        
        self.inputFieldButton.frame = self.inputField.bounds
        
        if (model == "6") {
            self.inputField.isHidden = false
            self.inputFieldButton.isHidden = false
        } else {
            if (self.showChat) {
                self.inputField.isHidden = false
                self.inputFieldButton.isHidden = false
            } else {
                self.inputField.isHidden = true;
                self.inputFieldButton.isHidden = true
            }
        }
    }
    @objc func podiumStatus(_ status:TalkfunApplyStatus)
    {
        if (status == .noApply) {
            self.ondium.setTitle("", for: .normal)
            self.ondium.setImage(UIImage.init(named: "HTLive.bundle/ondium"), for: .normal)
            self.ondium.backgroundColor = UIColor.clear
            self.ondium.imageEdgeInsets = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
        }else if (status == .applying || status == .allowInvite) {
            self.ondium.setTitle("取消", for: .normal)
            
            self.ondium.backgroundColor = UIColor(red: 23/255.0, green: 145/255.0, blue: 251/255.0 , alpha: 0.5)
            self.ondium.setTitleColor(UIColor.white, for: .normal)
         
            self.ondium.titleLabel!.font = UIFont.PingFang(size: 12)
            self.ondium.layer.cornerRadius = 18.5
            self.ondium.setImage(UIImage.init(named: "HTLive.bundle/"), for: .normal)
           
           
        }else{
//            self.ondium.setTitle("已上麦", for: .normal)
            self.ondium.setImage(UIImage.init(named: "HTLive.bundle/"), for: .normal)
      
            self.ondium.backgroundColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.5)
          
            self.ondium.layer.cornerRadius = 18.5
            self.ondium.setTitle("下麦", for: .normal)
          
            self.ondium.titleLabel!.font = UIFont.PingFang(size: 12)
            self.ondium.setTitleColor(UIColor.white, for: .normal)
            
        }
        

       
    }

    //添加点击事件
  @objc func backButtonAddTarget(_ target:NSObject,action:Selector)
    {
      self.back.addTarget(target, action: action, for: .touchUpInside)
    }
   @objc func updateModel(_ model:TalkfunRtcModel)
    {
        if (model.video == .closeForZHUBO || model.video == .closeForUser) {
            self.video.setImage(UIImage.init(named: "HTLive.bundle/videoOff1vN"), for: .normal)
               
            }else{
                self.video.setImage(UIImage.init(named: "HTLive.bundle/video1vN"), for: .normal)
              
            }

            
            if (model.audio == .closeForZHUBO || model.audio == .closeForUser) {
                self.audio.setImage(UIImage.init(named: "HTLive.bundle/audioOff1vN"), for: .normal)
                
            }else{
                self.audio.setImage(UIImage.init(named: "HTLive.bundle/audio1vN"), for: .normal)
                
            }

            
    }
    
}
